//
//  GGBLEManager.h
//  03-CL-Lock
//
//  Created by 陈志勇 on 16/9/23.
//  Copyright © 2016年 陈志勇. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

#define kServiceUUID @"6E400001-B5A3-F393-E0A9-E50E24DCCA9E" //易索电子钥匙服务的UUID
#define KEY_SERVICE_UUID  @"6e400001-b5a3-f393-e0a9-e50e24dcca9E" 
//#define KEY_CHARACTERISTIC_UUID_READ    @"6e400002-b5a3-f393-e0a9-e50e24dcca9E"
//#define KEY_CHARACTERISTIC_UUID_WHITE   @"6e400003-b5a3-f393-e0a9-e50e24dcca9E"
#define KEY_CHARACTERISTIC_UUID_WHITE    @"6e400002-b5a3-f393-e0a9-e50e24dcca9E"
#define KEY_CHARACTERISTIC_UUID_READ   @"6e400003-b5a3-f393-e0a9-e50e24dcca9E"

#define SDTT_CHARACTERISTIC_UUID_READ @"0000ff01-0000-1000-8000-00805f9b34fb"
#define SDTT_CHARACTERISTIC_UUID_WHITE @"0000ff02-0000-1000-8000-00805f9b34fb"

#define LOCK_SERVICE_UUID @"FFF0"
#define LOCK_CHARACTERISTIC_UUID_READWHITE   @"0000ffe1-0000-1000-8000-00805f9b34fb"

//蓝牙最大接受字节
#define QD_BLE_SEND_MAX_LEN 20

//电子钥匙名称
#define IKeyName @"DogLock"
#define IKeyName2 @"CL_Lock key"
#define IKeyName3 @"eLock_key"
//电子锁名称
#define ILockName @"HC-08"
#define ILockName2 @"CL_eLock"

@interface GGBLEManager : NSObject<CBCentralManagerDelegate,CBPeripheralDelegate>
@property(strong,nonatomic) CBCentralManager *theManager;
@property(strong,nonatomic) CBPeripheral *thePeripheral; //存储连接上的外设
@property(strong,nonatomic) CBCharacteristic *writeCha; //存储连接上外设的写特征
@property(strong,nonatomic) CBCharacteristic *notifyCha; //存储连接上外设的通知特征
@property(strong,nonatomic) NSMutableArray *peripheralList; //存储扫描到的外设
@property(strong,nonatomic) NSData *responseData; //存储蓝牙接收到的数据

@property(strong,nonatomic) void (^conReturnBlock)(CBCentralManager *central ,CBPeripheral *peripheral,NSString *stateStr);

@property(strong,nonatomic) void (^bluetoothListArr)(NSMutableArray *blueToothArray);

@property(strong,nonatomic) void (^responseDataReturnBlock)(NSData *responseData);

//创建单例类
+(instancetype)getInstance;

/**
 *  开始扫描
 */
- (void)startScan;

/**
 *  停止扫描
 */
- (void)stopScan;
/**
 *  获取蓝牙列表
 *
 *  @return 蓝牙列表
 */
-(NSMutableArray *)getNameList;

/**
 *  连接设备
 *
 *  @param per 选择的设备
 */
-(void)connectPeripheralWith:(CBPeripheral *)per;

/**
 *  打开通知
 */
-(void)openNotify:(CBCharacteristic *)cha;

/**
 *  关闭停止
 */
-(void)cancelNotify;

///**
// *  发送信息给蓝牙
// *
// *  @param infoData需要发送的data数据
// */
//- (void)sendData:(NSData *)infoData;
/**
 *  发送信息给蓝牙（分包）
 *
 *  @param msgData 需要发送的data数据
 */
-(void)sendMsgWithSubPackage:(NSData*)msgData;
/**
 *  断开连接
 *
 *  @param per需要连接的外设
 */
-(void)cancelPeripheralWith:(CBPeripheral *)per;
/**
 * 连接蓝牙状态信息回调
 * @param stateStr: 连接成功--SUCCESS，连接失败--ERROR，断开连接--DISCONNECT,无蓝牙信息--BLUEDISS
 **/
-(void)connectInfoReturn:(void(^)(CBCentralManager *central ,CBPeripheral *peripheral ,NSString *stateStr))myBlock;

/**
 *  蓝牙外设列表信息回调
 *
 *  @param listBlock 蓝牙外设列表
 */
-(void)getBlueListArray:(void (^)(NSMutableArray *blueToothArray))listBlock;

/**
 *  蓝牙外设收到数据时回调
 *
 *  @param myData蓝牙收到的数据
 */
-(void)responseReturn:(void(^)(NSData *responseData))myData;



@end
